package org.xbmc.android.xbmcremote;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class PhoneStateReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		XBMCApplication oXBMCApplication = (XBMCApplication)context.getApplicationContext();
		String action = intent.getAction();
		if(action.equals("android.intent.action.PHONE_STATE")) //PHONE_STATE_CHANGED_ACTION 
		{
			// Notify the Application that the phone is ringing...
			if(intent.getStringExtra("state").equals("RINGING"))
				oXBMCApplication.phoneCall(intent.getStringExtra("incoming_number"));
		}
		// This might be unsupported in a further version, look at that then (altough, its not a Broadcast...):
		/*
		MyPhoneStateListener phoneListener=new MyPhoneStateListener();
		TelephonyManager telephonyManager
		=(TelephonyManager)getSystemService(TELEPHONY_SERVICE);
		telephonyManager.listen(phoneListener,
		PhoneStateListener.LISTEN_CALL_STATE);

		public class MyPhoneStateListener extends PhoneStateListener {
		        Context context;
		        @Override
		        public void onCallStateChanged(int state,String incomingNumber){
		                 Log.e("PhoneCallStateNotified", "Incoming number "+incomingNumber);
		        }

		} 
		*/
	}

}
